package cn.lingyangwl.agile.food.core.controller.admin;

import cn.lingyangwl.agile.food.model.rqrs.sku.*;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.agile.food.core.service.StockDocumentService;
import cn.lingyangwl.framework.core.response.Resp;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 库存单据记录
 * 
 * @author shenguangyang
 */
@Api(tags = "库存单据记录")
@RestController
@RequestMapping("/skuStockInOut/record")
public class SkuStockInOutRecordController {
    @Resource
    private StockDocumentService stockDocumentService;

    @ApiOperation(value = "分页库存单据记录")
    @GetMapping("/page")
    @RamResource(action = "shopGoods:skuStockInOutRecord:query", name = "查询库存单据记录", type = ActionType.READ)
    public Resp<IPage<SkuInOutRecordResp>> pageRecord(@Validated SkuInOutRecordPageReq req) {
        return Resp.ok(stockDocumentService.pageRecord(req));
    }

    @ApiOperation(value = "通过id查找库存单据记录")
    @GetMapping("/get")
    @RamResource(action = "shopGoods:skuStockInOutRecord:query", name = "查询库存单据记录", type = ActionType.READ)
    public Resp<SkuInOutRecordResp> getRecord(@RequestParam(value = "id") Long id) {
        return Resp.ok(stockDocumentService.getRecord(id));
    }
  
    @ApiOperation(value = "保存库存单据记录")
    @PostMapping("/save")
    @RamResource(action = "shopGoods:skuStockInOutRecord:save", name = "保存库存单据记录", type = ActionType.WRITE)
    public Resp<?> saveRecord(@Validated @RequestBody SkuInOutRecordSaveReq req) {
        return Resp.ok(stockDocumentService.saveRecord(req));
    }
  
    @ApiOperation(value = "更新库存单据记录")
    @PostMapping("/update")
    @RamResource(action = "shopGoods:skuStockInOutRecord:update", name = "更新库存单据记录", type = ActionType.WRITE)
    public Resp<?> updateRecord(@Validated @RequestBody SkuInOutRecordUpdateReq req) {
        return Resp.ok(stockDocumentService.updateRecord(req));
    }
  
    @ApiOperation(value = "批量删除库存单据记录")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "shopGoods:skuStockInOutRecord:delete", name = "删除库存单据记录", type = ActionType.WRITE)
    public Resp<?> batchDeleteRecord(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(stockDocumentService.batchDeleteRecord(ids));
    }
  
    @ApiOperation(value = "删除库存单据记录")
    @DeleteMapping("/delete")
    @RamResource(action = "shopGoods:skuStockInOutRecord:delete", name = "删除库存单据记录", type = ActionType.WRITE)
    public Resp<?> deleteRecord(@RequestParam(value = "id") Long id) {
        return Resp.ok(stockDocumentService.deleteRecord(id));
    }
}
